package com.company.restaurant.service.convertor;

import com.company.restaurant.dto.BaseMessage;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

/**
 * Description of class.
 * Created 5/15/14 6:29 PM
 *
 * @author andrey.rodin@playtech.com
 */

public class JsonConverter implements Converter<String, BaseMessage> {

    private Gson gson = new Gson();
    private final Class type;

    public JsonConverter(Class type) {
        this.type = type;
    }

    @Override
    public BaseMessage convert(String source) {
        BaseMessage msg = null;
        try {
            msg = (BaseMessage) gson.fromJson(source, type);
        } catch (Exception ex) {

        }
        return msg;
    }
}
